package edu.szu.huhanpeng.doodlingFight 
{
	import edu.szu.huhanpeng.doodlingFight.controller.AppStartCmd;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import flash.display.Stage;
	import org.puremvc.as3.core.Controller;
	import org.puremvc.as3.core.Model;
	import org.puremvc.as3.core.View;
	import org.puremvc.as3.interfaces.IFacade;
	import org.puremvc.as3.patterns.facade.Facade;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class AppFacade extends Facade implements IFacade 
	{
		private static var _stage:Stage;
		
		public static function getInstance():AppFacade 
		{
			if (instance == null) 
			{
				instance = new AppFacade();
			}
			return instance as AppFacade;
		}
		
		override protected function initializeController():void 
		{
			super.initializeController();
			
			registerCommand( GlobalConst.noteName.APP_START, AppStartCmd );
		}
		
		public function start(stage:Stage):void
		{
			if (_stage == null) 
			{
				_stage = stage;
			}
			
			sendNotification( GlobalConst.noteName.APP_START, stage );
		}
		
		public static function forceReset():void
		{
			while ( _stage.numChildren != 0 )
			{
				_stage.removeChildAt(0);
			}
			instance = null;
			Model.forceReset();
			View.forceReset();
			Controller.forceReset();
			getInstance().start(_stage);
		}
		
		public function get stage():Stage 
		{
			return _stage;
		}
		
	}

}